from langchain_openai import ChatOpenAI
from langchain_core.output_parsers import StrOutputParser
import os

os.environ['OPENAI_API_KEY'] = 'sk-ioXCJ3W2IQlpDzHu268aEeF7CcAf4b1f9f8c46A248C74a9d'
os.environ['OPENAI_BASE_URL'] = 'https://api.xiaoai.plus/v1'

if __name__ == '__main__':

    ### 输出解析器，将多余消息过滤，只需要回答字符串
    output_parser = StrOutputParser()

    llm = ChatOpenAI()
    llm.model_name = 'gpt-4'

    ###  组合LLM链
    chain = llm | output_parser

    print(chain.invoke("xxxa多研究院是谁出资建立的？"))

